package edu.ynu.MyProject.controller;

import edu.ynu.MyProject.common.controller.LogicController;
import edu.ynu.MyProject.dao.IEquipmentDAO;
import edu.ynu.MyProject.entity.Equipment;
import edu.ynu.MyProject.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@Api(tags = "设备")
@RestController
@RequestMapping("/device")
public class EquipmentController extends LogicController<EquipmentService, IEquipmentDAO, Equipment, Long> {
    private final EquipmentService equipmentService;

    public EquipmentController(@Autowired EquipmentService equipmentService) {
        super(equipmentService);
        this.equipmentService = equipmentService;
    }

    @ApiOperation("获取传感器数据")
    @GetMapping("/value/{greenhouseId}")
    public ResponseEntity<List<Map<String, Object>>> getDataByGreenhouseId(@PathVariable Long greenhouseId) {
        return equipmentService.getDeviceData(greenhouseId);
    }

    @ApiOperation("获取摄像头截屏")
    @GetMapping("/capture/{greenhouseId}")
    public Map<String, Object> getCaptureByGreenhouseId(@PathVariable Long greenhouseId) {
        return equipmentService.getCameraCapture(greenhouseId);
    }
}
